#include "ttestwindow.h"
#include "singleton.h"
#include "QtNetwork"
#include "singleton.h"
#include "tnetworkmanager.h"
#include "iostream"

TTestWindow::TTestWindow(QWidget *parent) :
    QWidget(parent),
    notifications (&Singleton<TNotify>::Instance()),
    notifyButton (new QPushButton("Notification test", this)),
    showCookiesButton (new QPushButton("Show Cookies")),
    layout (new QGridLayout(this))
{
    this->setLayout(layout);
    layout->addWidget(notifyButton, 0,0);
    layout->addWidget(showCookiesButton, 0,1);
    QObject::connect(notifyButton, SIGNAL(clicked()), this, SLOT(showNotification()));
    QObject::connect(showCookiesButton, SIGNAL(clicked()), this, SLOT(showCookies()));
}

void TTestWindow::showNotification(){
    notifications->newNotify("Test subject", "alksdfanef;klanself;knasleknfalsienflasneflknaslefknleknfsdvasvasevasevasefasefasefasefasefasefal");
}

void TTestWindow::showCookies(){
    std::cout <<"List of cookies:" <<std::endl;
    QNetworkAccessManager* nm = &Singleton<TNetworkManager>::Instance();
    QList<QNetworkCookie> cookieList = nm->cookieJar()->cookiesForUrl(QUrl(QString("http://dobrochan.ru")));
    for(int i=0; i < cookieList.count(); i++){
	std::cout << QString(cookieList.at(i).name()).toStdString() << ": " << QString(cookieList.at(i).value()).toStdString() <<std::endl;
    }
}
